package com.baidu.health.service;

import com.baidu.health.mapper.TbArticleMapper;
import com.baidu.health.pojo.TbArticle;
import com.baidu.health.pojo.resultVo.resultVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.health.pojo.TbDocument;
import com.baidu.health.mapper.TbDocumentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbDocumentServiceImpl extends ServiceImpl<TbDocumentMapper, TbDocument>{

    @Autowired
    TbDocumentMapper documentMapper;

    @Autowired
    TbArticleMapper articleMapper;

    public resultVo getDocumentList() {
        List<TbDocument> documentList = documentMapper.selectList(null);
        return new resultVo(200,"查询成功",documentList);
    }

    public resultVo checkFile(Integer fileStatus, TbDocument document) {
        TbArticle tbArticle = articleMapper.selectOne(new QueryWrapper<TbArticle>().lambda().eq(TbArticle::getArticleId, document.getArticleId()));
        tbArticle.setCheckFlag(fileStatus);
        tbArticle.setUpdateTime(new Date());
        articleMapper.updateById(tbArticle);
        documentMapper.deleteById(document);
        return new resultVo(200,"审核完成",null);
    }
}




